package start.spring.basic.job.service.jobmonitor.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import start.spring.basic.constant.CommonConstant;
import start.spring.basic.job.dao.GgJobLogMapper;
import start.spring.basic.job.entity.GgJobLog;
import start.spring.basic.job.service.BaseServiceImpl;
import start.spring.basic.job.service.jobmonitor.IGgJobLogService;
import start.spring.basic.page.PageQuery;
import start.spring.basic.page.PageResult;
import start.spring.basic.util.common.StringUtil;

/**
 * JOB历史执行日志Service业务层处理
 * 
 * @author xyy
 * @date 2023-06-27
 */
@Service
public class GgJobLogServiceImpl extends BaseServiceImpl implements IGgJobLogService {
    
    @Autowired
    private GgJobLogMapper ggJobLogMapper;

    /**
     * 查询JOB历史执行日志列表
     * 
     * @param ggJobLog JOB历史执行日志
     * @return JOB历史执行日志
     */
    @Override
    public PageResult<GgJobLog> selectGgJobLogPageList(PageQuery pageQuery,GgJobLog ggJobLog) {
        IPage<GgJobLog> page = super.getPage(pageQuery);
        QueryWrapper<GgJobLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(!StringUtil.isEmpty(ggJobLog.getJobclass()), GgJobLog::getJobclass, ggJobLog.getJobclass());
    	queryWrapper.lambda().eq(!StringUtil.isEmpty(ggJobLog.getStatus()), GgJobLog::getStatus, ggJobLog.getStatus());
        if(!StringUtil.isEmpty(ggJobLog.getBeginKssj()) && !StringUtil.isEmpty(ggJobLog.getEndKssj())) {
        	queryWrapper.lambda().between(GgJobLog::getKssj, ggJobLog.getBeginKssj() + CommonConstant.SURFIX_DATE_BEGIN, ggJobLog.getEndKssj() + CommonConstant.SURFIX_DATE_END);
        }
        queryWrapper.lambda().orderByDesc(GgJobLog::getKssj);
        page = this.ggJobLogMapper.selectPage(page, queryWrapper);
        return super.getPageResult(page);
    }
    
}
